package util

import (
	"strconv"
	"strings"
)

func Unique[C any](arr []C) []C {
	var d = make(map[any]bool)
	var res []C
	for _, c := range arr {
		if _, ok := d[c]; !ok {
			res = append(res, c)
			d[c] = true
		}
	}
	return res
}

func String2Int64Array(str string) []int64 {
	if str == "" {
		return []int64{}
	}
	strArr := strings.Split(str, ",")
	var arr []int64
	for _, s := range strArr {
		strInt64, err := strconv.ParseInt(s, 10, 64)
		if err == nil {
			arr = append(arr, strInt64)
		}
	}
	return Unique(arr)
}
